from dao import Dao
from model.user import User

class UserDao(Dao):
    def __init__(self):
        """Arguments:
            collection --- string the name of the collection
        """
        Dao.__init__(self, User)
        self.collection = 'users'

    def insert(self, user):
        """Save the user object to collection
        Arguments:
            user --- The User Model object
        """
        if isinstance(user, User):
            # Insert except ID field, because ID will be automatically generated
            _dict = {}
            _dict['username'] = user.username;
            _dict['password'] = user.password;
            _dict['email'] = user.email;
            _dict['role'] = user.role;
            _dict['phone'] = user.phone;
            _dict['description'] = user.description;
            _dict['created'] = user.created;
            
            return self.db.insert(self.collection, _dict)
        return None
    
